package com.coolbi.onsupai.core.util;

import java.util.Date;

import com.coolbi.common.util.DateUtil;
import com.coolbi.onsupai.core.entity.Coupon;
import com.coolbi.onsupai.core.exception.ServiceException;

public class CouponUtils {

	public static void validateCoupon(Coupon coupon) {
		Date currentDate = new Date();
		if (coupon == null) {
			throw new ServiceException("该优惠券不存在或已被使用");
		}
		if (! DateUtil.compareDate(currentDate, coupon.getEffectiveDate())) {
			throw new ServiceException("该优惠券尚未到生效时间");
		}
		if (DateUtil.compareDate(currentDate, coupon.getFutileDate())) {
			throw new ServiceException("该优惠券已失效");
		}
	}
}
